package com.sam.mooc;

/**
 * 最长上升子序列的长度
 * 以ak(k=1,2,3...n) 为结尾的最张子序列的长度
 * Created by samwang on 2017/12/20.
 */
public class MaxLengAscSubArray {
    public static void main(String[] args) {
        int[] a = {1, 7, 3, 5, 9, 4, 8, 10, 2};// result 5
        int result = maxAscLength(a);
        System.out.println(result);
    }

    public static int maxAscLength(int[] a) {
        int[] maxLens = new int[a.length];
        int result = 1;
        for (int i = 0; i < a.length; i++) {
            maxLens[i] = 1;
            for (int j = 0; j < i; j++) {
                if (a[j] < a[i]) {
                    int thisMax = maxLens[j] + 1;
                    if (thisMax > maxLens[i]) {
                        maxLens[i] = thisMax;
                    }
                }
            }
            if (maxLens[i] > result) {
                result = maxLens[i];
            }
        }


        return result;
    }

}
